<?php

final class Gravatar extends Nette\Application\UI\Control
{
	private $default = 'mm';
	private $rating = 'pg';
	private $server = 'http://www.gravatar.com/avatar/';

	/**
	 * Return url of Gravatar
	 * @param string $email
	 * @param int $size
	 * @return string
	 */
	private function getUrl($email = '', $size = 32)
	{
		$url = $this->server.$email.'?s='.$size.'&d='.$this->default.'&r='.$this->rating;
		return $url;
	}

	/**
	 * Render Gravatar
	 * @param string $email
	 * @param int $size
	 */
	public function render($email = '', $size = 32)
	{
		$this->template->url = $this->getUrl($email, $size);

		$this->template->setFile(__DIR__ . '/Gravatar.latte');
		$this->template->render();
	}

	/**
	 * Render big Gravatar
	 * @param string $email
	 * @param int $size
	 */
	public function renderBig($email = '', $size = 64)
	{
		$this->render($email, $size);
	}
}
